package com.example.simplegridview;

import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class simplegrid extends AppCompatActivity {

    private int[] picture = {R.mipmap.img01, R.mipmap.img02, R.mipmap.img03, R.mipmap.img04, R.mipmap.img05, R.mipmap.img06, R.mipmap.img07, R.mipmap.img08, R.mipmap.img09, R.mipmap.img10, R.mipmap.img11, R.mipmap.img12,};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simplegrid);

        GridView gridView = (GridView) findViewById(R.id.gridView);
        List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();

        for (int i = 0; i < picture.length; i++) {
            Map<String, Object> map = new HashMap<String, Object>(picture.length);
            map.put("image", picture[i]);
            listItems.add(map);

        }

        SimpleAdapter simpleAdapter = new SimpleAdapter(simplegrid.this, listItems, R.layout.gridviewlayout, new String[]{"image"}, new int[]{R.id.image});

        gridView.setAdapter(simpleAdapter);
    }
}